import json

from flask import render_template,request,jsonify
from . import log_manage

import os
from frameworks.cores.Config import *
from frameworks.utils.JsonResult2 import *
from frameworks.cores.LoadClass import *

basepath = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
config = Config(basepath)

apimap = config.getApi()
env = apimap["base"]
print(env)
from flask_session import Session

jsonResult = JsonResult2()

loader = LoadClass()

@log_manage.route('/actor_log/list')
def actor_log_list():
    return render_template('log_manage/actor_log_list.html')

@log_manage.route(env+"/actor_log/cols",methods=['GET','POST'])
def actor_log_cols():
    rs = loader.load("controller.log_manage.ActorLogController", "ActorLogController", {
        "func":"getColumns",
        "fields":["id","actor_id","type","content","ctime","mtime"]
    })
    return jsonResult.setOk(rs,"获取成功")

@log_manage.route(env+"/actor_log/page",methods=['GET'])
def actor_log_page():
    num = request.args.get("limit",10)
    page = request.args.get("page",1)
    data = loader.load("controller.log_manage.ActorLogController", "ActorLogController", {
        "func": "getData",
        "fields": ["id","actor_id","type","content","ctime","mtime"],
        "page": page,
        "num": num,
        "orderfield": "id",
        "asc": "asc"
    })
    return json.dumps(data)